import type { ConsultType } from '@/enums'
import type { ConsuleIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'consult',
  () => {
    const consult = ref<PartialConsult>({})
    const setType = (type: ConsultType) => {
      consult.value!.type = type
    }
    const setIllnessType = (type: 0 | 1) => {
      consult.value!.illnessType = type
    }
    const setDep = (type: string) => {
      consult.value!.depId = type
    }
    const setIllness = (illness: ConsuleIllness) => {
      consult.value!.illnessDesc = illness.illnessDesc
      consult.value!.illnessTime = illness.illnessTime
      consult.value!.consultFlag = illness.consultFlag
      consult.value!.pictures = illness.pictures
    }
    const setPatient = (id: string) => {
      consult.value!.patientId = id
    }
    const setCoupon = (id: string) => {
      consult.value!.couponId = id
    }
    const clear = () => (consult.value = {})
    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear
    }
  },
  {
    persist: true
  }
)
